const Koa = require('koa');
const {serveStaticPlugin} = require('./plugins/serverPluginServerStatic');
const {moduleRewritePlugin} = require('./plugins/serverPluginModuleRewrite');

function createServer(){
  const app = new Koa();
  const root = process.cwd();

  console.log(root);

  const context = {
    app,
    root, // 当前的根的位置
  };

  const resolvePlugins = [ // 插件的集合
    // 2) 解析import 重写路径
    moduleRewritePlugin,

    // 1) 静态服务
    serveStaticPlugin
  ];

  resolvePlugins.forEach(plugin => plugin(context));

  return app;
}

module.exports = createServer;
